package com.gitee.huanminabc.utils_tools.web_cloud.config;

import com.gitee.huanminabc.utils_tools.web_base.config.RestTemplateConfig;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
@Configuration
public class RestCloudTemplateConfig extends RestTemplateConfig {

    @LoadBalanced  // 开启负载均衡   如果不需要那么就注释掉  ,开启负载后必须使用服务名
    @Bean
    public RestTemplate restTemplate(ClientHttpRequestFactory factory) {
        RestTemplate restTemplate = new RestTemplate(factory);
        MyResponseErrorHandler errorHandler = new MyResponseErrorHandler();
        restTemplate.setErrorHandler(errorHandler);
//        List<HttpMessageConverter<?>> messageConverters = restTemplate.getMessageConverters();
        // 通过下面代码可以添加新的 HttpMessageConverter
        //messageConverters.add(new );
        return restTemplate;
    }



}
